package cn.hwm.proxy.rpcdemo;

import java.util.concurrent.ConcurrentHashMap;

public class DepotServiceImpl implements DepotService{

    private static ConcurrentHashMap<String, Integer> goodsData = new ConcurrentHashMap<>();

    static {
        goodsData.put("001", 1000);
        goodsData.put("002", 2000);
        goodsData.put("003", 3000);
        goodsData.put("004", 4000);
        goodsData.put("005", 5000);
    }

    @Override
    public void inDepot(String goodsId, int addAmout) {
        System.out.println("+++++++++++++++++++++++++增加商品：" + goodsId + "库存，数量为：" + addAmout);
        int i = goodsData.get(goodsId) + addAmout;
        goodsData.put(goodsId, i);
        System.out.println("+++++++++++++++++++++++++增加商品：" + goodsId + "库存，数量变为：" + i);
    }

    @Override
    public void outDepot(String goodsId, int outAmout) {
        System.out.println("+++++++++++++++++++++++++减少商品：" + goodsId + "库存，数量为：" + outAmout);
        int i = goodsData.get(goodsId) - outAmout;
        goodsData.put(goodsId, i);
        System.out.println("+++++++++++++++++++++++++减少商品：" + goodsId + "库存，数量变为：" + i);
    }
}
